<template>
  <el-dialog
    v-if="visible"
    custom-class="mediate-dialog"
    :visible="visible"
    title="操作权限"
    width="1000px"
    @close="handleClose"
  >
    <auth-tree ref="authTree" :auth-key-list="authKeyList" :right-str="modalFormData.rightStr" :is-admin="modalFormData.isAdmin" />
    <span slot="footer" class="dialog-footer" size="small">
      <el-button v-if="!modalFormData.isAdmin && !isHideButtons" type="primary" size="small" @click="handleSubmit">提交</el-button>
      <el-button size="small" @click="handleClose">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { authKey } from '@/config/authKey'
import AuthTree from '@/components/AuthTree'

export default {
  name: 'OperateAuth',
  components: { AuthTree },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    modalFormData: { // 数据
      type: Object,
      default: () => ({})
    },
    isHideButtons: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      authKeyList: authKey // 权限Key
    }
  },
  methods: {
    handleSubmit() { // 提交
      this.modalFormData.rightStr = this.$refs.authTree.rightList.join(',')
      this.$emit('handleSubmit', this.modalFormData)
    },
    handleClose() { // 关闭
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-footer {
  display: flex;
  justify-content: center;
}
</style>
